﻿package core.ui.dialogs
{
    import core.event.*;
    import core.ui.controls.*;
    import flash.events.*;

    public class CanvasSizeDialog extends Dialog
    {
        var anchor:int = 1;
        var oh:int;
        var ow:int;
        var tbw:Dropslider;
        var tbh:Dropslider;
        var cp:Checkbox;
        var a1:Markbox;
        var a2:Markbox;
        var a3:Markbox;
        var a4:Markbox;
        var a5:Markbox;
        var a6:Markbox;
        var a7:Markbox;
        var a8:Markbox;
        var a9:Markbox;

        public function CanvasSizeDialog(param1:Tuyitu)
        {
            super(param1, "rm_canvas_size", 320, 190, true);
            this.oh = param1.canvas.document.dh;
            this.ow = param1.canvas.document.dw;
            var _loc_2:* = new Literal("rm_anchor", true);
            _loc_2.x = 10;
            _loc_2.y = 90;
            _loc_2.width = 70;
            addChild(_loc_2);
            this.a1 = new Markbox(1);
            this.a1.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a1.x = 82;
            this.a1.y = 90;
            this.a1.Mark();
            addChild(this.a1);
            this.a2 = new Markbox(2);
            this.a2.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a2.x = 106;
            this.a2.y = 90;
            addChild(this.a2);
            this.a3 = new Markbox(3);
            this.a3.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a3.x = 130;
            this.a3.y = 90;
            addChild(this.a3);
            this.a4 = new Markbox(4);
            this.a4.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a4.x = 82;
            this.a4.y = 114;
            addChild(this.a4);
            this.a5 = new Markbox(5);
            this.a5.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a5.x = 106;
            this.a5.y = 114;
            addChild(this.a5);
            this.a6 = new Markbox(6);
            this.a6.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a6.x = 130;
            this.a6.y = 114;
            addChild(this.a6);
            this.a7 = new Markbox(7);
            this.a7.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a7.x = 82;
            this.a7.y = 138;
            addChild(this.a7);
            this.a8 = new Markbox(8);
            this.a8.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a8.x = 106;
            this.a8.y = 138;
            addChild(this.a8);
            this.a9 = new Markbox(9);
            this.a9.addEventListener(NumberEvent.CHANGE, this.SetAnchor);
            this.a9.x = 130;
            this.a9.y = 138;
            addChild(this.a9);
            var _loc_3:* = new Literal("rm_height", true);
            _loc_3.x = 10;
            _loc_3.y = 55;
            _loc_3.width = 70;
            addChild(_loc_3);
            this.tbh = new Dropslider(55, 0, 4000, this.oh);
            this.tbh.x = 80;
            this.tbh.y = 55;
            addChild(this.tbh);
            var _loc_4:* = new Literal("rm_pixels");
            _loc_4.x = 138;
            _loc_4.y = 55;
            addChild(_loc_4);
            var _loc_5:* = new Literal("rm_width", true);
            _loc_5.x = 10;
            _loc_5.y = 30;
            _loc_5.width = 70;
            addChild(_loc_5);
            this.tbw = new Dropslider(55, 0, 4000, this.ow);
            this.tbw.x = 80;
            this.tbw.y = 30;
            addChild(this.tbw);
            var _loc_6:* = new Literal("rm_pixels");
            _loc_6.x = 138;
            _loc_6.y = 30;
            addChild(_loc_6);
            var _loc_7:int = 239;
            cancel.x = 239;
            ok.x = _loc_7;
            ok.y = 25;
            cancel.y = 54;
            return;
        }// end function

        private function SetAnchor(event:NumberEvent) : void
        {
            this.a1.Unmark();
            this.a2.Unmark();
            this.a3.Unmark();
            this.a4.Unmark();
            this.a5.Unmark();
            this.a6.Unmark();
            this.a7.Unmark();
            this.a8.Unmark();
            this.a9.Unmark();
            switch(event.val)
            {
                case 1:
                {
                    this.a1.Mark();
                    this.anchor = 1;
                    break;
                }
                case 2:
                {
                    this.a2.Mark();
                    this.anchor = 2;
                    break;
                }
                case 3:
                {
                    this.a3.Mark();
                    this.anchor = 3;
                    break;
                }
                case 4:
                {
                    this.a4.Mark();
                    this.anchor = 4;
                    break;
                }
                case 5:
                {
                    this.a5.Mark();
                    this.anchor = 5;
                    break;
                }
                case 6:
                {
                    this.a6.Mark();
                    this.anchor = 6;
                    break;
                }
                case 7:
                {
                    this.a7.Mark();
                    this.anchor = 7;
                    break;
                }
                case 8:
                {
                    this.a8.Mark();
                    this.anchor = 8;
                    break;
                }
                case 9:
                {
                    this.a9.Mark();
                    this.anchor = 9;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override public function OKClick(event:MouseEvent) : void
        {
            if (this.tbw.value != this.ow || this.tbh.value != this.oh)
            {
                ed.canvas.ResizeCanvas(this.tbw.value, this.tbh.value, this.anchor);
            }
            Close();
            return;
        }// end function

    }
}
